#include <iostream>
#include <stdio.h>
#include <cmath>

using namespace std;
int bj(string a,string b);
string gjd_minus(string a,string b);

int c[100];
int d[100];
int e[100];

int main() {
    int n = 0;
    cin >> n;
    string max;
    string min;
    cin >> max;
    min = max;
    for(int i = 0; i < n-1; i++){
        string a;
        cin >> a;
        if(bj(a,max)){
            max = a;
        }
        if(bj(min,a)){
            min = a;
        }
    }
    cout << gjd_minus(max,min) ;
}

int bj(string a, string b){
    int len1 = a.length();
    int len2 = b.length();
    if((len1 < len2)||(len1 == len2 && a < b)){
        return 0;
    }
    else{
        return 1;
    }
}

string gjd_minus(string a,string b){
    int len1 = a.length();
    int len2 = b.length();
    int flag = 0;
    if((len1 < len2)||(len1 == len2 && a < b)){
        swap(a,b);
        flag = 1;
        len1 = a.length();
        len2 = b.length();
    }
    for(int i = 0; i < len1; i++){
        c[i] = int(a[len1-i-1])-48;
    }
    for(int i = 0; i < len2; i++){
        d[i] = int(b[len2-i-1])-48;
    }
    int t = 0;
    for(int i = 0; i < len1; i++){
        e[i] = c[i]-d[i]-t;
        
        if(e[i] < 0){
            e[i] = c[i]+10-d[i]-t;
            t = 1;
        }
        else{
            t = 0;
        }
    }
    int m = 0;
    for(int i = 99; i >= 0; i--){
        if(e[i] == 0){
            m+=1;
        }
        else{
            break;
        }
    }
    string u="";
    if(flag){
        u+='-';
    }
    for(int i = 0; i <= 99-m; i++){
        u+= e[99-m-i]+48;
    }
    return u;
}